package com.fei.service;

import com.fei.bean.MusicBean;
import com.fei.bean.SingerBean;
import com.fei.bean.SongListMusicBean;
import com.fei.mapper.SingerMapper;
import com.fei.mapper.SongListMusicMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SongListMusicServiceImpl implements SongListMusicService{

    @Autowired
    SongListMusicMapper songListMusicMapper;
    @Autowired
    SingerMapper singerMapper;
    @Autowired
    MusicService musicService;

    @Override
    public List<MusicBean> findAllOneSingIdService(int song_list_id, int singer_id) {
        List<MusicBean> musicBeanList = musicService.selectOneSingerIdService(singer_id);
//        所有的歌单中所有的singer_id
        List<Integer> musicId = songListMusicMapper.findAllOneSingId(song_list_id,singer_id);
        if(musicBeanList != null){
            if(musicId != null){
                for (int i = 0;i<musicId.size();i++){
                    for(int j = 0;j<musicBeanList.size();j++){
                        if(musicId.get(i) == musicBeanList.get(j).getId()){
                            musicBeanList.remove(j);
                        }
                    }
                }
            }
        }
        return musicBeanList;
    }

    @Override
    public int insertSongListMusicService(List<SongListMusicBean> bean) {
        return songListMusicMapper.insertSongListMusic(bean);
    }

    @Override
    public List<SongListMusicBean> selectOneIdSong(int song_list_id) {
        List<SongListMusicBean> music = songListMusicMapper.selectOneIdSong(song_list_id);
        return music;
    }

    @Override
    public int deleteOneIdService(int id) {
        return songListMusicMapper.deleteOneId(id);
    }

    @Override
    public int deleteAllOneSongListIdService(int song_list_id) {
        return songListMusicMapper.deleteAllOneSongListId(song_list_id);
    }


}
